const { $wx, $http, globalData, role, img } = getApp()
Page({
    data: {
        img,
    },
    onLoad: function (options) {
       const token = $wx.local('token')
       if(token){
           $wx.pushTab('/pages/index/index')
       }
    },
    onSubmit(e){
        const { user_name, password } = e.detail.value
        if(user_name === ''){ return $wx.toast('请输入手机号') }  // 15952016252 / 13028123093 / 15952016253
        if(password === ''){ return $wx.toast('请输入密码') }     // 123456
        $wx.localClear()
        $http.submit(this,'user.login', { 
            param:{ user_name, password }, 
            noToken:true, 
            loadingText:'登录中...',
            succeedText:'登录成功',
            tab:'/pages/index/index'
        } ).then(( { token, userinfo } )=>{
            $wx.local('user', userinfo)
            $wx.local('token', token)
            globalData.list = role[userinfo.user_type]
        })
    }
})